package com.bcu.alumnus.repo;

import com.bcu.alumnus.entity.Activity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Repository
public interface ActivityRepository extends JpaRepository<Activity, Integer>, JpaSpecificationExecutor {

    /**
     *
     *1. 通过学部编号查找已审核的校园活动
     *2. 通过创建人编号查找已审核的校园活动
     *3. 查找校级活动
     *4. 通过活动创建人编号和活动状态查找校园活动
     *5. 通过学部编号查找所有活动
     *6. 查找所有的活动
     *7. 通过活动状态查找所有活动
     *8. 通过活动类型查找所有的活动
     *9. 通过活动编号查找活动
     *10. 修改活动状态
     */

    List<Activity> getActivityByActPartIdAndActStatusNot(String actPartId,String actStatus);

    List<Activity> getActivityByActUserId(String actUserId);


    @Query(value="select * from activity where act_part_id=?1 and act_status='1' or act_status='1' and act_type='2'order by act_create_time desc",nativeQuery = true)
    List<Activity> getActivityForMiniProgram(String actPartId);
//    select news_id,news_title,news_author,news_date,news_title_img from news where news_part_id=?1 and news_status=1 or news_type=2 and news_status=1 order by news_date desc
//    List<Activity> getActivityByActPartIdAndActTypeAndActStatusNot(String actPartId,Strin:wqg ActType,String Status);



    List<Activity> getActivityByActUserIdAndActStatus(String actUserId,String ActStatus);

    List<Activity> getActivityByActPartId(String actPartId);

    @Override
    List<Activity> findAll();

    List<Activity> getActivityByActStatus(String actStatus);

    List<Activity> getActivityByActType(String ActType);

    Activity getActivityByActId(int ActId);

    List<Activity> getActivityByActStatusAndActPartId(String actType,String actPartId);

    @Transactional
    @Modifying
    @Query(value = "update Activity  set actStatus=?1 where actId=?2")
    int updataActStatusByActId(String ActStatus,int ActId);

    @Query(value = "select act_member_way from activity where act_id=?1",nativeQuery = true)
    String getActMemberWay(int ActId);

    List<Activity> getActivityByActTitle(String actTitly);

    int deleteByActId(int ActId);

}
